local nya__shangshi = fk.CreateSkill {

  name = "nya__shangshi",

  tags = {  },

}



nya__shangshi:addEffect(fk.HpChanged, {
  name = "nya__shangshi",
  anim_type = "drawcard",
  events = {fk.HpChanged, fk.MaxHpChanged, fk.AfterCardsMove, fk.EventAcquireSkill, fk.EventLoseSkill},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(nya__shangshi.name) then
      if event == fk.EventAcquireSkill or event == fk.EventLoseSkill then
        if target == player and data.name == "nya__play" then
          return player.room:getTag("RoundCount")  --防止游戏开始添加技能时触发
        end
      elseif event == fk.EventLoseSkill then
        return target == player and data.name == "nya__play"
      elseif player:getHandcardNum() < math.max(player:getLostHp(), 1) then
        if event == fk.AfterCardsMove then
          for _, move in ipairs(data) do
            return move.from==player
          end
        elseif event == fk.HpChanged or event == fk.MaxHpChanged then
          return target == player
        end
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.EventAcquireSkill then
      player.room:changeMaxHp(player, -1)
    elseif event == fk.EventLoseSkill then
      player.room:changeMaxHp(player, 1)
    else
      player:drawCards(math.max(player:getLostHp(), 1) - player:getHandcardNum(), nya__shangshi.name)
    end
  end,
})
nya__shangshi:addEffect(fk.MaxHpChanged, {
  name = "nya__shangshi",
  anim_type = "drawcard",
  events = {fk.HpChanged, fk.MaxHpChanged, fk.AfterCardsMove, fk.EventAcquireSkill, fk.EventLoseSkill},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(nya__shangshi.name) then
      if event == fk.EventAcquireSkill or event == fk.EventLoseSkill then
        if target == player and data.name == "nya__play" then
          return player.room:getTag("RoundCount")  --防止游戏开始添加技能时触发
        end
      elseif event == fk.EventLoseSkill then
        return target == player and data.name == "nya__play"
      elseif player:getHandcardNum() < math.max(player:getLostHp(), 1) then
        if event == fk.AfterCardsMove then
          for _, move in ipairs(data) do
            return move.from==player
          end
        elseif event == fk.HpChanged or event == fk.MaxHpChanged then
          return target == player
        end
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.EventAcquireSkill then
      player.room:changeMaxHp(player, -1)
    elseif event == fk.EventLoseSkill then
      player.room:changeMaxHp(player, 1)
    else
      player:drawCards(math.max(player:getLostHp(), 1) - player:getHandcardNum(), nya__shangshi.name)
    end
  end,
})
nya__shangshi:addEffect(fk.AfterCardsMove, {
  name = "nya__shangshi",
  anim_type = "drawcard",
  events = {fk.HpChanged, fk.MaxHpChanged, fk.AfterCardsMove, fk.EventAcquireSkill, fk.EventLoseSkill},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(nya__shangshi.name) then
      if event == fk.EventAcquireSkill or event == fk.EventLoseSkill then
        if target == player and data.name == "nya__play" then
          return player.room:getTag("RoundCount")  --防止游戏开始添加技能时触发
        end
      elseif event == fk.EventLoseSkill then
        return target == player and data.name == "nya__play"
      elseif player:getHandcardNum() < math.max(player:getLostHp(), 1) then
        if event == fk.AfterCardsMove then
          for _, move in ipairs(data) do
            return move.from==player
          end
        elseif event == fk.HpChanged or event == fk.MaxHpChanged then
          return target == player
        end
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.EventAcquireSkill then
      player.room:changeMaxHp(player, -1)
    elseif event == fk.EventLoseSkill then
      player.room:changeMaxHp(player, 1)
    else
      player:drawCards(math.max(player:getLostHp(), 1) - player:getHandcardNum(), nya__shangshi.name)
    end
  end,
})
nya__shangshi:addEffect(fk.EventAcquireSkill, {
  name = "nya__shangshi",
  anim_type = "drawcard",
  events = {fk.HpChanged, fk.MaxHpChanged, fk.AfterCardsMove, fk.EventAcquireSkill, fk.EventLoseSkill},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(nya__shangshi.name) then
      if event == fk.EventAcquireSkill or event == fk.EventLoseSkill then
        if target == player and data.name == "nya__play" then
          return player.room:getTag("RoundCount")  --防止游戏开始添加技能时触发
        end
      elseif event == fk.EventLoseSkill then
        return target == player and data.name == "nya__play"
      elseif player:getHandcardNum() < math.max(player:getLostHp(), 1) then
        if event == fk.AfterCardsMove then
          for _, move in ipairs(data) do
            return move.from==player
          end
        elseif event == fk.HpChanged or event == fk.MaxHpChanged then
          return target == player
        end
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.EventAcquireSkill then
      player.room:changeMaxHp(player, -1)
    elseif event == fk.EventLoseSkill then
      player.room:changeMaxHp(player, 1)
    else
      player:drawCards(math.max(player:getLostHp(), 1) - player:getHandcardNum(), nya__shangshi.name)
    end
  end,
})
nya__shangshi:addEffect(fk.EventLoseSkill, {
  name = "nya__shangshi",
  anim_type = "drawcard",
  events = {fk.HpChanged, fk.MaxHpChanged, fk.AfterCardsMove, fk.EventAcquireSkill, fk.EventLoseSkill},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(nya__shangshi.name) then
      if event == fk.EventAcquireSkill or event == fk.EventLoseSkill then
        if target == player and data.name == "nya__play" then
          return player.room:getTag("RoundCount")  --防止游戏开始添加技能时触发
        end
      elseif event == fk.EventLoseSkill then
        return target == player and data.name == "nya__play"
      elseif player:getHandcardNum() < math.max(player:getLostHp(), 1) then
        if event == fk.AfterCardsMove then
          for _, move in ipairs(data) do
            return move.from==player
          end
        elseif event == fk.HpChanged or event == fk.MaxHpChanged then
          return target == player
        end
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.EventAcquireSkill then
      player.room:changeMaxHp(player, -1)
    elseif event == fk.EventLoseSkill then
      player.room:changeMaxHp(player, 1)
    else
      player:drawCards(math.max(player:getLostHp(), 1) - player:getHandcardNum(), nya__shangshi.name)
    end
  end,
})

return nya__shangshi